package jp.co.cos.ittrick.channel.controller.client;

import jp.co.cos.ittrick.channel.meta.ChapterModelMeta;
import jp.co.cos.ittrick.channel.model.ChapterModel;
import jp.co.cos.ittrick.channel.service.ChapterService;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;

public class GetChapterController extends Controller {

    private ChapterService chapterService;

    public GetChapterController() {
        chapterService = new ChapterService();
    }

    @Override
    public Navigation run() throws Exception {

        // リクエストパラメータ
        String chapter = asString("chapter");

        ChapterModel chapterModel = chapterService.getChapterByKey(Integer.valueOf(chapter));

        response.setCharacterEncoding("utf-8");
        response.setContentType("application/json");
        response.getWriter().println(ChapterModelMeta.get().modelToJson(chapterModel));
        response.flushBuffer();

        return null;
    }
}
